#ifndef __HTML_PARSER_FACTORY_H__
#define __HTML_PARSER_FACTORY_H__

#include "HtmlParser.h"

class CHtmlParserFactory
{
public:
	CHtmlParser * CreateHtmlParser(const CString & strUrl);
};

CHtmlParser * CHtmlParserFactory::CreateHtmlParser(const CString & strUrl)
{
	static struct URLCODE{
		TCHAR	szUrl[MAX_PATH];
		UINT	nSiteCode;
	}URLDIC[] = {
		{_T("amazon.cn"),		AMAZON_CODE},
		{_T("dangdang.com"),	DANGDANG_CODE}
	};
	int nCode = UNKNOWN_CODE;
	int nCount = sizeof(URLDIC)/sizeof(URLCODE);
	for (int i = 0; i < nCount; ++i)
	{
		if (strUrl.Find(URLDIC[i].szUrl) >= 0)
		{
			nCode = URLDIC[i].nSiteCode;
			break;
		}
	}

	switch (nCode)
	{
	case AMAZON_CODE:
		return new CAmazonParser(strUrl, nCode);
	case DANGDANG_CODE:
		return new CDangdangParser(strUrl, nCode);
	default:
		return NULL;
	}
}

#endif